package actions;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;

import javax.ejb.EJB;

import beans.*; import entities.*;

public class PendingAction extends ActionSupport{

	
	public ArrayList<Request> pending;
	public ArrayList<Request> recalled;
	@EJB
    LoanManager loanMan=new LoanManagerBean();
	
	private static final long serialVersionUID = 4L;

	public String execute() {
		Object userIdObj=ActionContext.getContext().getSession().get("userId");
		if(userIdObj==null){
			this.addActionError("You must login to view this page");
			return ERROR;
		}
		Object oldErr=ActionContext.getContext().getSession().get("error");
		Object oldMessage=ActionContext.getContext().getSession().get("message");
		ActionContext.getContext().getSession().remove("error");
		ActionContext.getContext().getSession().remove("message");
	    if(oldErr!=null)this.addActionError(oldErr.toString());
	    if(oldMessage!=null)this.addActionMessage(oldMessage.toString());
		int userId=((Integer)userIdObj).intValue();
		pending=loanMan.getPendingLoans(userId);
		int len=(pending==null)?0:pending.size();
		this.addActionMessage("Number of requests " + len);
		
		return SUCCESS;
		
	}
}
